import json

import requests


class KWMusic:
    url = "https://www.kuwo.cn/api/v1/www/music/playUrl?mid=%s&type=music&httpsStatus=1&reqId=d97c9830-ed07-11ef-bb71-e5ddb0d2449d&plat=web_www&from="

    payload = {}
    headers = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Cache-Control": "no-cache",
        "Connection": "keep-alive",
        "Cookie": "gtoken=Vz5mmkmW9uk6; gid=d62cb12f-772d-4ef1-bef5-63c44dbb4488; Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1739775289; HMACCOUNT=0918E9374F8EFB4E; _ga=GA1.2.1461956199.1739775301; _gid=GA1.2.1293561616.1739775301; JSESSIONID=15k3yovymap6n1fnrptyvzjxxp; _gat=1; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1739780687; _ga_ETPBRPM9ML=GS1.2.1739779361.2.1.1739780686.36.0.0; Hm_Iuvt_cdb524f42f23cer9b268564v7y735ewrq2324=iCGz6MNXbJMX4dr26FEyYrFiaJdhr37w",
        "Host": "www.kuwo.cn",
        "Pragma": "no-cache",
        "Referer": "https://www.kuwo.cn/play_detail/208247320",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "Secret": "4a13ccd8276a2673bc6fedc97fdec31f3e89b4ae6e88da6e68ca1ff1f4b552fb03711e29",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
        "sec-ch-ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Windows\""
    }

    def getPath(self, id):
        okurl = self.url % (id)
        response = requests.request("GET", okurl, headers=self.headers, data=self.payload)
        print(response.text)
        print(response.text)
        loads = json.loads(response.text)
        return {
            "wma": loads["data"]["url"],
            "m4a": loads["data"]["url"],
        }
